package com.engine4cloud.tdf.supervision.convert;

import com.engine4cloud.tdf.common.core.constant.enums.CorFileTypeEnum;
import com.engine4cloud.tdf.common.security.service.TdfUser;
import com.engine4cloud.tdf.supervision.dto.JzdxFileDTO;
import com.engine4cloud.tdf.supervision.dto.query.JzdxFileQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.JzdxFileResultDTO;
import com.engine4cloud.tdf.supervision.entity.JzdxFileEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface JzdxFileConvert {
    JzdxFileConvert INSTANCE = Mappers.getMapper(JzdxFileConvert.class);

    @Mapping(target = "id", ignore = true)
    JzdxFileEntity createTo(JzdxFileDTO s);

    JzdxFileResultDTO convert(JzdxFileEntity s);

    JzdxFileEntity convertTo(JzdxFileResultDTO s);

    default JzdxFileEntity create(String code, String dcCode, String batch, CorFileTypeEnum fileType, JzdxFileDTO dto, TdfUser u) {
        JzdxFileEntity entity = createTo(dto);
        entity.setRybh(code);
        entity.setDcpgbh(dcCode);
        entity.setLcbh(batch);
        entity.setFileType(fileType);
        entity.setTenantId(u.getTenantId());
        return entity;
    }

    default List<JzdxFileEntity> createList(JzdxFileQueryDTO dto, List<JzdxFileDTO> fileList, TdfUser u) {
        return fileList.stream().map(file -> JzdxFileConvert.INSTANCE.create(dto.getRybh(), dto.getDcpgbh(), dto.getLcbh(), dto.getFileType(), file, u)).toList();
    }

    default List<JzdxFileEntity> convert(List<JzdxFileResultDTO> s) {
        return s.stream().map(JzdxFileConvert.INSTANCE::convertTo).toList();
    }
}
